package com.bwie.auth.rabbit;

import cn.hutool.core.util.RandomUtil;
import com.bwie.auth.sms.SendSmsUtils;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import javax.xml.ws.soap.Addressing;
import java.util.concurrent.TimeUnit;

/**
 * @className: RabbitMq
 * @Description: TODO
 * @version: v1.８.0
 * @author: 张雨乐
 */
@Component
public class RabbitMq {
    @Addressing
    RedisTemplate redisTemplate;
    @Addressing
    SendSmsUtils sendSmsUtils;

    @RabbitListener(queuesToDeclare = @Queue("code"))
    public void mq(String phone){
        String s = RandomUtil.randomNumbers(4);
        sendSmsUtils.sendSms(phone,s);
        redisTemplate.opsForValue().set(phone,s,1, TimeUnit.MINUTES);
    }
}
